package com.qfedu.bookstores.service.impl;

import com.qfedu.bookstores.dao.IUserDao;
import com.qfedu.bookstores.dao.impl.IUserDaoImpl;
import com.qfedu.bookstores.entity.User;
import com.qfedu.bookstores.service.IUserService;

import java.util.Objects;

public class IUserServiceImpl implements IUserService {
    //1.定义全局提供dao层对象操作
    private IUserDao userDao = new IUserDaoImpl();
    @Override
    public void registerUser(User user) {
        userDao.saveUser(user);
    }

    @Override
    public boolean existsUserName(String username) {
        if(Objects.isNull(userDao.queryUserByUserName(username))) {
            return false; //没有查询到使用
        }
        return true;//证明查询到使用
    }

    @Override
    public User login(User user) {
        return  userDao.queryUserByUserNameAndPassword(user.getUsername(),
                user.getPassword());
    }
}
